package com.jtjrenren.android.taxi.driver.core.wallect;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;


import com.jtjrenren.android.taxi.driver.bean.DriverInfo;
import com.jtjrenren.android.taxi.driver.manger.AppManger;
import com.jtjrenren.android.taxi.driver.utils.UIHelper;
import com.jtjrenren.android.taxi.driver.R;

import com.jtjrenren.android.taxi.driver.bean.api.ApiSrResult;
import com.jtjrenren.android.taxi.driver.base.BaseActivity;
import com.jtjrenren.android.taxi.driver.manger.api.ApiWorks;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/6.
 */
public class WallectSrmxActivity extends BaseActivity {
    private SwipeRefreshLayout srf;
    private RecyclerView rcy_list;

    private IncomeHistoryAdapter adapter;
    private List<ApiSrResult.IncomeListEntity> list;
    private DriverInfo driver;

    @Override
    public int getLayoutID() {
        return R.layout.aty_common_listview;
    }

    @Override
    public void init() {

        driver = AppManger.getInstance().driver;
        list = new ArrayList<>();

        srf = (SwipeRefreshLayout) findViewById(R.id.listview_wrf);
        rcy_list = (RecyclerView) findViewById(R.id.listview_rcy);

        ((TextView) findViewById(R.id.title_title)).setText("收入明细");
        findViewById(R.id.title_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        UIHelper.initVritalReclyView(this, rcy_list);
        UIHelper.initSwipeRefreshLayout(srf);

        adapter = new IncomeHistoryAdapter(this);
        adapter.setList(list);
        rcy_list.setAdapter(adapter);

        srf.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getSrMx();
            }
        });

        getSrMx();
    }

    private void getSrMx() {
        if (driver == null)
            return;
        ApiWorks.getSrHistory(driver.getWorkNo(), 60, 1, new ApiWorks.ResponseListener<ApiSrResult>() {
            @Override
            public void onResponse(ApiSrResult apiSrResult) {
                if (srf.isRefreshing())
                    srf.setRefreshing(false);
                if (apiSrResult != null && apiSrResult.getIncomeList().size() > 0)
                    adapter.replace(apiSrResult.getIncomeList());

            }
        });
    }
}
